<!DOCTYPE html>
<html class="x-admin-sm" xmlns:th="http://www.thymeleaf.org">

<head>
    <meta charset="UTF-8">
    <title>欢迎</title>
    <th:block th:include="include::header"/>
</head>
<body>
<div class="layui-fluid">
    <div class="layui-row">
        <form class="layui-form" th:object="${equip}">
            <input type="hidden" id="id" name="id" th:value="*{id}" required="" lay-verify="">
            <div class="layui-form-item">
                <label for="type" class="layui-form-label">
                    <span class="x-red"></span>设备种类</label>
                <div class="layui-input-inline">
                    <input type="text" id="type" disabled="disabled" name="type" th:value="*{type}" required="" lay-verify=""
                           autocomplete="off" class="layui-input"></div>
            </div>
            <div class="layui-form-item">
                <label for="test1" class="layui-form-label">
                    开始时间 </label>
                <div class="layui-input-inline">
                    <input type="text" name="begin" th:value="*{begin}" class="layui-input" id="test1"
                           placeholder="yyyy-MM-dd HH:mm:ss"></div>
            </div>
            <div class="layui-form-item">
                <label for="test2" class="layui-form-label">
                    结束时间</label>
                <div class="layui-input-inline">
                    <input type="text" name="end" th:value="*{end}" class="layui-input" id="test2"
                           placeholder="yyyy-MM-dd HH:mm:ss"></div>
            </div>
            <div class="layui-form-item">
                <label for="name" class="layui-form-label">
                    <span class="x-red"></span>姓名</label>
                <div class="layui-input-inline">
                    <input type="text" id="name" th:value="*{name}" name="name" required="" lay-verify=""
                           autocomplete="off" class="layui-input"></div>
            </div>
            <!--<div id="summernote" name="intro"></div>-->
            <div class="layui-form-item">
                <div id="summernote"></div>
            </div>
            <div class="layui-form-item">
                <button class="layui-btn" lay-filter="edit" lay-submit="">修改</button>
            </div>
        </form>
    </div>
</div>
<script th:inline="javascript" type="text/javascript">

    // 初始化富文本
    $(document).ready(function () {
        $('#summernote').summernote();
    });
    //赋值
    var intro = [[${equip.getIntro()}]];
    $('#summernote').summernote('code', intro);

</script>
<script>layui.use(['form', 'layer', 'jquery'],
    function () {
        $ = layui.jquery;
        var form = layui.form,
            layer = layui.layer;
        //监听提交
        form.on('submit(edit)',
            function (data) {
                var summernote = $("#summernote").summernote("code");
                data.field.intro=summernote;
                console.log(data);
                console.log(data.field);
                //发异步，把数据提交给php
                $.ajax({
                    url: "/equip/edit",
                    type: "POST",
                    data: data.field,
                    success(res) {
                        if (res.success) {
                            layer.msg("修改成功", {
                                    icon: 6,
                                    time: 600
                                },
                                function () {
                                    //关闭当前frame
                                    xadmin.close();
                                });
                        } else {
                            layer.msg(res.msg)
                        }
                    }
                })
                return false;
            });

    });</script>
<!--日期-->
<script>
    layui.use('laydate', function () {
        var laydate = layui.laydate;
        //日期时间选择器
        laydate.render({
            elem: '#test1'
            , type: 'datetime'
        });
        laydate.render({
            elem: '#test2'
            , type: 'datetime'
        });
        //前后若干天可选，这里以7天为例
        laydate.render({
            elem: '#test-limit2'
            , min: -7
            , max: 7
        });
        //同时绑定多个
        lay('.test-item').each(function () {
            laydate.render({
                elem: this
                , trigger: 'click'
            });
        });
    });
</script>
</body>

</html>